﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;
using System.Collections.Specialized;
using AjaxControlToolkit;

namespace CalendarMgm.asmx
{
    /// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {
        [WebMethod]
        public CascadingDropDownNameValue[] getProvinces(string knownCategoryValues, string category)
        {
            StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);    //解析已知的内容
            List<CascadingDropDownNameValue> provinceList = new List<CascadingDropDownNameValue>();

            try
            {
                XmlDocument doc = new XmlDocument();
                // 装入指定的XML文档
                doc.Load("C:\\Users\\Frankie\\Documents\\Visual Studio 2008\\Projects\\CalendarMgm\\CalendarMgm\\xml\\ProvincesCities.xml");
                XmlNodeList readNode = doc.SelectNodes("CityServiceSource");
                int provinceCount = doc.ChildNodes[1].ChildNodes.Count;
                for (int i = 0; i < provinceCount; i++)
                {
                    string tempName = doc.ChildNodes[1].ChildNodes[i].Attributes["name"].Value;
                    provinceList.Add(new CascadingDropDownNameValue(tempName, tempName));
                }
            }
            catch (System.Exception e)
            {
            	
            }
            finally
            {
            }
            return provinceList.ToArray();
        }

        [WebMethod]
        public CascadingDropDownNameValue[] getCities(string knownCategoryValues, string category)
        {
            StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);    //解析已知的内容
            List<CascadingDropDownNameValue> CityList = new List<CascadingDropDownNameValue>();

            try
            {
                XmlDocument doc = new XmlDocument();
                // 装入指定的XML文档
                doc.Load("C:\\Users\\Frankie\\Documents\\Visual Studio 2008\\Projects\\CalendarMgm\\CalendarMgm\\xml\\ProvincesCities.xml");
                XmlNodeList readNode = doc.SelectNodes("CityServiceSource");
                int provinceCount = doc.ChildNodes[1].ChildNodes.Count;
                for (int i = 0; i < provinceCount; i++)
                {
                    string tempProvince = doc.ChildNodes[1].ChildNodes[i].Attributes["name"].Value;

                    if (tempProvince.Equals(kv["province"]))
                    {
                        XmlNodeList tempCityList = doc.ChildNodes[1].ChildNodes[i].ChildNodes;
                        int tempCityListCount = tempCityList.Count;

                        for (int j = 0; j<tempCityListCount;j++ )
                        {
                            string tempName = tempCityList[j].Attributes["name"].Value;
                            CityList.Add(new CascadingDropDownNameValue(tempName, tempName));
                        }
                    } 
                }
            }
            catch (System.Exception e)
            {

            }
            finally
            {
            }

            return CityList.ToArray();
        }

    }
}
